package com.chw.controller;

import com.chw.common.ChwData;
import com.chw.model.vo.UserVo;
import com.chw.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

@Controller
@RequestMapping("/user")
public class User {
    @Autowired
    private  IUserService iUserService;
    @RequestMapping("area")
    @ResponseBody
    public ChwData area(Integer pid){
        return ChwData.success(iUserService.area(pid));
    }
    @RequestMapping("addUser")
    @ResponseBody
    public ChwData addUser(com.chw.model.User user) throws MessagingException, UnsupportedEncodingException {

        return ChwData.success(iUserService.addUser(user));
    }
    @RequestMapping("isExit")
    @ResponseBody
    public ChwData isExit(String name,String password){

         return ChwData.success(iUserService.isExit(name, password));
    }
    @RequestMapping("queryUser")
    @ResponseBody
    public ChwData queryUser(UserVo userVo){

         return ChwData.success(iUserService.queryUser(userVo));
    }
    @RequestMapping("upUser")
    @ResponseBody
    public ChwData upUser(com.chw.model.User user){

        iUserService.upUser(user);
         return ChwData.success("");
    }
     @RequestMapping("upPass")
    @ResponseBody
    public ChwData upPass(String name,Integer id, String password,String password1){


         return ChwData.success(iUserService.upPass(name,id,password,password1));
    }

    @RequestMapping("toCreateUser")
    public String toCreateUser(String page){
        return page;
    }
    @RequestMapping("loginto")
    public String  loginto(HttpServletRequest request){
        request.getSession().removeAttribute("login_user");
        return "redirect:/login.jsp";
    }

}
